<!DOCTYPE html>
<html>
  <head>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta content="yes" name="apple-mobile-web-app-capable" />
  <meta content="black" name="apple-mobile-web-app-status-bar-style" />
  <meta name="referrer" content="never">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <meta name="author" content="kveln">
  <title>Centos7.4使用rke V1.1.9安装K8s集群 | John Wong&#39;s Blog</title>
  <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
  <!-- <link href="https://blog.jwangkun.com/media/css/bootstrap.min.css" rel="stylesheet"> -->
  <!--  <link href="https://blog.jwangkun.com/media/css/all.min.css" rel="stylesheet" type="text/css"> -->
  <link href="https://cdn.bootcss.com/font-awesome/5.11.2/css/all.min.css" rel="stylesheet">
  <link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
  <link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
  <link rel="alternate" type="application/rss+xml" title="Centos7.4使用rke V1.1.9安装K8s集群 | John Wong&#39;s Blog » Feed" href="https://blog.jwangkun.com/atom.xml">
  <link rel="stylesheet"href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.10/build/styles/androidstudio.min.css">
  <link href="https://blog.jwangkun.com/styles/main.css" rel="stylesheet">
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.15.10/build/highlight.min.js"></script>
  <!-- <script src="https://blog.jwangkun.com/media/scripts/jquery.min.js"></script> -->
  <script>hljs.initHighlightingOnLoad();</script>
  

    <meta property="og:description" content="Centos7.4使用rke V1.1.9安装K8s集群"/>
    <meta property="og:url" content="https://blog.jwangkun.com/post/9zKNF0siQ/"/>
    <meta property="og:locale" content="zh-CN"/>
    <meta property="og:type" content="website"/>
    <meta property="og:site_name" content="John Wong&#39;s Blog"/>
  </head>
  <body>
  	<!-- Navigation -->
  <nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
    <div class="container">
      <a class="navbar-brand" href="https://blog.jwangkun.com">John Wong&#39;s Blog</a>
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
        Menu
        <i class="fas fa-bars"></i>
      </button>
      <div class="collapse navbar-collapse" id="navbarResponsive">
        <ul class="navbar-nav ml-auto">
          
          <li class="nav-item">
              
              <a class="nav-link" href="/">首页</a>
              
          </li>
          
          <li class="nav-item">
              
              <a class="nav-link" href="/archives">归档</a>
              
          </li>
          
          <li class="nav-item">
              
              <a class="nav-link" href="/tags">标签</a>
              
          </li>
          
          <li class="nav-item">
              
              <a class="nav-link" href="/post/about">关于</a>
              
          </li>
          
        </ul>
      </div>
    </div>
  </nav>
  <!-- Page Header -->
  <header class="masthead" style="background-image: url('https://blog.jwangkun.com/media/images/home-bg.jpg')">
    <div class="overlay"></div>
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <div class="post-heading">
          	<span class="tags">
          	 
            <a href="https://blog.jwangkun.com/tag/ioorEHano/" class="tag">RKE</a>
            
            <a href="https://blog.jwangkun.com/tag/efVGHoi38/" class="tag">Kubernetes</a>
            
        </span>
            <h1>Centos7.4使用rke V1.1.9安装K8s集群</h1>
            <span class="meta">
            	Posted on
              2020-10-15，6 min read
            </span>
          </div>
        </div>
      </div>
    </div>
  </header>

  <!-- Post Content -->
  <article>
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <p>Rancher Kubernetes引擎(RKE)是一个cncf认证的Kubernetes发行版，它可以在裸机和虚拟化服务器上工作。RKE解决了Kubernetes安装复杂性的问题，有了RKE, Kubernetes的安装和操作既简化又易于自动化，而且完全独立于您正在运行的操作系统和平台。只要可以运行受支持的Docker版本，就可以使用RKE部署和运行Kubernetes。</p>
<!-- more -->
<h3 id="环境准备">环境准备</h3>
<p>更新yum源并安装docker</p>
<pre><code>yum update -y

yum install docker -y
</code></pre>
<p>然后使之生效</p>
<pre><code>systemctl daemon-reload
</code></pre>
<p>设置docker开机自启</p>
<pre><code>systemctl enable docker
</code></pre>
<p>启动docker</p>
<pre><code>systemctl start docker
</code></pre>
<p>关闭防火墙：</p>
<pre><code> $ systemctl stop firewalld
 $ systemctl disable firewalld
 $ iptables -F
</code></pre>
<p>关闭selinux：</p>
<pre><code> $ sed -i &quot;s/^SELINUX=enforcing/SELINUX=disabled/g&quot; /etc/selinux/config
 $ sed -i &quot;s/^SELINUX=permissive/SELINUX=disabled/g&quot; /etc/selinux/config
 $ setenforce 0
 $ cat /etc/selinux/config
</code></pre>
<p>永久禁用swap，注释掉swap项</p>
<pre><code># vi /etc/fstab  
</code></pre>
<p>配置yum 国内源</p>
<pre><code class="language-bash"># 备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
# 下载国内源到/etc/yum.repo.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo &lt;http://mirrors.aliyun.com/repo/Centos-7.repo&gt;
</code></pre>
<p>性能调优</p>
<pre><code>cat &gt;&gt; /etc/sysctl.conf&lt;&lt;EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF
sysctl -p
</code></pre>
<h3 id="rke安装">RKE安装</h3>
<p>https://github.com/rancher/rke/releases</p>
<p>下载二进制包，并解压rke_linux-amd64重命名为rke</p>
<pre><code> chmod +x rke
 rke --version
</code></pre>
<p>查看rke支持的Kubernetes版本</p>
<pre><code>$ rke config --list-version --all
v1.15.3-rancher2-1
v1.13.10-rancher1-2
v1.14.6-rancher2-1
v1.16.0-beta.1-rancher1-1
</code></pre>
<h3 id="安装k8s集群">安装k8s集群</h3>
<p>编辑yml文件https://rancher.com/docs/rke/latest/en/example-yamls/#minimal-cluster-yml-example，注意缩进</p>
<pre><code> cat cluster.yml
</code></pre>
<pre><code>#节点信息
nodes:  
 #master和etcd节点
  - address: 10.0.32.1 
    user: docker_user
    role: [controlplane,etcd]
#工作节点
  - address: 10.0.32.2 
    user: docker_user
    ssh_key_path: ~/.ssh/id_rsa
    role: [worker]
  - address: 10.0.32.3
    ssh_key_path: ~/.ssh/id_rsa
    user: docker_user
    role: [worker]
#服务信息
services: 
   etcd:
     image: quay.io/coreos/etcd:latest  
   kube-api:
     pod_security_policy: false
     image: rancher/k8s:v1.8.5-rancher4     
     service_cluster_ip_range: 10.233.0.0/18
   kube-controller:
     cluster_cidr: 10.233.64.0/18  
     image: rancher/k8s:v1.8.5-rancher4  
   scheduler:
     image: rancher/k8s:v1.8.5-rancher4  
   kubelet:
     cluster_domain: cluster.local
     cluster_dns_server: 10.233.0.3 
     infra_container_image: gcr.io/google_containers/pause-amd64:3.0     
     image: rancher/k8s:v1.8.5-rancher4  
    kubeproxy:
     image: rancher/k8s:v1.8.5-rancher4
#网络模式
network: 
  plugin: flannel
#镜像
system_images:
  flannel: rancher/coreos-flannel:v0.9.1  
  kubedns: rancher/k8s-dns-kube-dns-amd64:1.14.5  
  dnsmasq: rancher/k8s-dns-dnsmasq-nanny-amd64:1.14.5  
  kubedns_sidecar: rancher/k8s-dns-sidecar-amd64:1.14.5  
  kubedns_autoscaler: rancher/cluster-proportional-autoscaler-amd64:1.0.0  
  dashboard: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3
#认证模式
authentication: 
  strategy: x509
</code></pre>
<p>注意，要增加一个普通用户，rke不支持root安装</p>
<pre><code> useradd rancher
 passwd rancher
 usermod -aG dockerroot rancher
 service docker restart
 chmod a+rw /var/run/docker.sock
</code></pre>
<p>免密登录，在master 10.0.32.1上执行</p>
<pre><code>#ssh-keygen

#ssh-copy-id rancher@10.0.32.1
#ssh-copy-id rancher@10.0.32.2
#ssh-copy-id rancher@10.0.32.3
</code></pre>
<p>注意YML文件中的用户指建立的用户</p>
<pre><code>./rke0.2.0 up --config ./cluster.yml
</code></pre>
<p>完成后当前目录会生成kube_config_cluster.yml文件和cluster.rkestate文件,把kube_config_rancher-cluster.yml文件复制为 ~/.kube/config</p>
<pre><code>export KUBECONFIG=/home/admin/kube_config_cluster.yml
mkdir ~/.kube
cp kube_config_rancher-cluster.yml ~/.kube/config
</code></pre>
<h3 id="安装kubectl">安装kubectl</h3>
<p>增加YUM库</p>
<pre><code>cat &lt;&lt;EOF &gt; /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg &lt;https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg&gt;
EOF
</code></pre>
<p>更新YUM</p>
<pre><code>yum update -y
</code></pre>
<p>执行安装</p>
<pre><code>yum -y install kubelet kubeadm kubectl
</code></pre>
<p>测试</p>
<pre><code>kubctl version 
</code></pre>
<p>通过RKE安装k8s集群成功,启动的时候有些节点启动的比较慢。需要稍微等待一段时间</p>
<p>查看pods的状态，都启动成功及表示安装成功</p>
<pre><code>kubectl get pods -A
</code></pre>
<h3 id="安装-helm">安装 helm</h3>
<p>https://github.com/helm/helm/releases</p>
<pre><code>helm init --client-only --stable-repo-url https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts/
helm repo add incubator https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/
helm repo update
</code></pre>
<h2 id="kubectl和helm命令补全">kubectl和helm命令补全</h2>
<pre><code>yum install -y bash-completion
source &lt;(kubectl completion bash)
echo &quot;source &lt;(kubectl completion bash)&quot; &gt;&gt; ~/.bashrc
source &lt;(helm completion bash)
echo &quot;source &lt;(helm completion bash)&quot; &gt;&gt; ~/.bashrc
source /usr/share/bash-completion/bash_completion
</code></pre>
<h3 id="安装网络插件"><strong>安装网络插件</strong></h3>
<p>RKE是一个幂等工具，可以运行多次，且每次均产生相同的输出。如下的网络插件它均可以支持部署：</p>
<ul>
<li>Calico</li>
<li>Flannel (default)</li>
<li>Canal</li>
</ul>
<p>要使用不同的网络插件，您可以在配置文件中指定：</p>
<pre><code>network: 
    plugin: calico
</code></pre>
<h3 id="添加删除集群节点">添加删除集群节点</h3>
<p>要添加其他节点，只需要更新具有其他节点的集群配置文件，并使用相同的文件运行集群配置即可</p>
<pre><code>rke up --update-only
</code></pre>
<h3 id="删除集群">删除集群</h3>
<pre><code>rke removecluster.yml
</code></pre>

          
          <p class="next-post">下一篇：
            <a href="https://blog.jwangkun.com/post/x1hHMvXKi/">
              <span class="post-title">
                使用KubeKey安装Kubernetes1.18.6 以及KubeSphere 3.0&rarr;
              </span>
            </a>
          </p>
        
        <div class="comment">
          
        </div>
      </div>
    </div>
  </article>
 <!-- Footer -->
  <footer>
    <div class="container">
      <div class="row">
        <div class="col-lg-8 col-md-10 mx-auto">
          <ul class="list-inline text-center">
            
            
              
            
              
            
              
            
              
            
              
            
              
            
              
              <li class="list-inline-item">
              <a href="https://blog.jwangkun.com/atom.xml" target="_blank">
                <span class="fa-stack fa-lg">
                  <i class="fas fa-circle fa-stack-2x"></i>
                  <i class="fas fa-rss fa-stack-1x fa-inverse"></i>
                </span>
              </a>
              </li>
          </ul>
          <p class="copyright text-muted">Copyright &copy;<span>John Wong&#39;s Blog</span><br><a href="https://github.com/getgridea/gridea" class="Themeinfo">Powered by Gridea</a></p>
        </div>
      </div>
    </div>
   </footer>
  <!-- Bootstrap core JavaScript -->
  <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
  <!-- <script src="https://blog.jwangkun.com/media/scripts/bootstrap.bundle.min.js"></script> -->
  <!-- Bootstrap core JavaScript -->
  <script src="https://cdn.jsdelivr.net/gh/Alanrk/clean-cdn@1.0/scripts/clean-blog.min.js"></script>
  <!-- <script src="https://blog.jwangkun.com/media/scripts/clean-blog.min.js"></script> -->
  <script src="//instant.page/3.0.0" type="module" defer integrity="sha384-OeDn4XE77tdHo8pGtE1apMPmAipjoxUQ++eeJa6EtJCfHlvijigWiJpD7VDPWXV1"></script>
  <style type="text/css">a.back_to_top{text-decoration:none;position:fixed;bottom:40px;right:30px;background:#f0f0f0;height:40px;width:40px;border-radius:50%;line-height:36px;font-size:18px;text-align:center;transition-duration:.5s;transition-propety:background-color;display:none}a.back_to_top span{color:#888}a.back_to_top:hover{cursor:pointer;background:#dfdfdf}a.back_to_top:hover span{color:#555}@media print,screen and(max-width:580px){.back_to_top{display:none!important}}</style>
<a id="back_to_top" href="#" class="back_to_top">
  <span>▲</span></a>
<script>$(document).ready((function(_this) {
    return function() {
      var bt;
      bt = $('#back_to_top');
      if ($(document).width() > 480) {
        $(window).scroll(function() {
          var st;
          st = $(window).scrollTop();
          if (st > 30) {
            return bt.css('display', 'block')
          } else {
            return bt.css('display', 'none')
          }
        });
        return bt.click(function() {
          $('body,html').animate({
            scrollTop: 0
          },
          800);
          return false
        })
      }
    }
  })(this));
  var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?84ab85460bfbe79dbe5776a1df139a8f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
  </script>
  
<script type="text/javascript" src="https://v1.cnzz.com/z_stat.php?id=1279350888&web_id=1279350888"></script>

  </body>
</html>

